package com.srx.openfeign.utils;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;

/**
 * 返回结果工具类
 * <p>统一返回结果</p>
 * @author 沈汝旭
 * @since 2025-10-18 10:54
 * @version 1.0
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
@Accessors(chain = true)
public class ResultUtil<T>
{


	/**
	 * 响应码
	 */
	@Schema(description = "响应码", example = "200")
	private Integer code;
	/**
	 * 响应信息
	 */
	@Schema(description = "响应信息", example = "成功")
	private String message;
	/**
	 * 响应数据
	 */
	@Schema(description = "响应数据", example = "{name:'沈汝旭',age:23}")
	private T data;
	/**
	 * 响应数量
	 */
	@Schema(description = "响应数量", example = "14")
	private Integer count;



	/**
	 * 返回结果
	 *
	 * @param data 返回的数据
	 * @param <T>  数据类型
	 * @return 统一返回结果
	 */
	public static <T> ResultUtil<T> createResult(Integer code, String message, T data, Integer count)
	{
		return new ResultUtil<T>()
				.setCode(code)
				.setMessage(message)
				.setData(data)
				.setCount(count);
	}


}
